/****************************************************************************
* This file is part of qtmount, a simple system tray application for mounting and mounting removable media using udisks.
* Copyright (C) 2010 Aleksey Kamenskikh
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>
*
* Contact e-mail: aleksey.kamenskikh@gmail.com
*
****************************************************************************/


#pragma once
#include <QApplication>
#include <QVariant>
#include <QIcon>
#include <QWidget>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QAction>
#include <QDBusInterface>
#include <QDBusReply>
#include <QDBusError>
#include <QDebug>

#define UDISKSSERVICE "org.freedesktop.UDisks"

class QDBusConnection;

class Tray : public QWidget
  {
  	Q_OBJECT
  	
  public:
  	Tray();
 
  private slots:
  	void iconActivated(QSystemTrayIcon::ActivationReason reason);
		void deviceAdded(QDBusObjectPath devicePath);
  	void itemClicked();
		void mountError(QDBusError error);
		void mountResult(QString mountPath);
		void unmountError(QDBusError error);
		void unmountResult();

  private:
  	QMenu *trayMenu;
  	QSystemTrayIcon *trayIcon;
  	QAction *quitAction;
		QIcon mountIcon;
		QIcon unmountIcon;
  	void createMenu();
  	void createActions();
  	void createTrayIcon();
		QVariant getUdisksDeviceProperty(QString devicepath, QString parametername);
		void mountDevice(QString devicepath);
		void unmountDevice(QString devicepath);
		QString udisksErrorToMessage(QString errorName);
  };
